package com.xiaozhou.controller;

import com.xiaozhou.pojo.dto.LoginReqDto;
import com.xiaozhou.pojo.vo.SysUserVo;
import com.xiaozhou.result.Result;
import com.xiaozhou.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * CTassName: UserController
 * Package: com.xiaozhou.controller
 * Description:
 * 登录接口
 */
@RestController
@RequestMapping("/api")
@Slf4j
public class UserController {

    /**
     * 用户登录 业务层
     */
    @Autowired
    private UserService userService;

    /**
     * 验证码⽣成功能
     */
    @GetMapping("/captcha")
    public Result<Map> captcha() {
        log.info("验证码⽣成功能");
        return userService.getCaptchaCode();
    }


    /**
     * 用户登录功能
     */
    @PostMapping("/login")
    public Result<SysUserVo> login(@RequestBody LoginReqDto loginReqDto) {

        log.info("用户登录功能，数据：{}", loginReqDto);

        SysUserVo sysUserVo = userService.login(loginReqDto);


        return Result.success(sysUserVo);
    }
}
